import numpy as np
import matplotlib.pyplot as plt
from matplotlib.animation import FuncAnimation
from mpl_toolkits.mplot3d import Axes3D

fig = plt.figure()
ax = fig.add_subplot(111, projection="3d")

# 饼图的半径
radius = 1.5


# 定义圆环的点，用于绘制饼图
def circle_points(theta, r):
    x = r * np.cos(theta)
    y = r * np.sin(theta)
    return x, y


# 绘制饼图的部分
def draw_pie(ax, theta, r):
    x, y = circle_points(theta, r)
    ax.clear()
    ax.plot(x, y, "o", zs=0, zdir="z")
    ax.set_xlim(-r, r)
    ax.set_ylim(-r, r)
    ax.set_zlim(0, r)


# 初始化角度数组和半径数组
theta = np.linspace(0, 2 * np.pi, 100)
r = np.ones(len(theta)) * radius


# 创建动画
def update(frame):
    # 根据时间来更新饼图的角度和半径
    r[:] = radius * (1 + np.sin(theta + frame / 10.0)) / 2.0
    draw_pie(ax, theta, r)


# 创建动画对象
ani = FuncAnimation(fig, update, frames=np.arange(0, 100), interval=10)

# 显示动画
plt.show()
